<script type="text/javascript">
    jQuery.noConflict();

    jQuery(document).ready(function() {

//	prettyPrint();			//syntax highlighter
        mainwrapperHeight();
        responsive();

        // widget icons dashboard
        if (jQuery('.widgeticons').length > 0) {
            jQuery('.widgeticons a').hover(function() {
                jQuery(this).find('img').addClass('animate0 bounceIn');
            }, function() {
                jQuery(this).find('img').removeClass('animate0 bounceIn');
            });
        }


        // it's below the document height
        function mainwrapperHeight() {
            var windowHeight = jQuery(window).height();
            var mainWrapperHeight = jQuery('.mainwrapper').height();
            var leftPanelHeight = jQuery('.leftpanel').height();
            if (leftPanelHeight > mainWrapperHeight)
                jQuery('.mainwrapper').css({minHeight: leftPanelHeight});
            if (jQuery('.mainwrapper').height() < windowHeight)
                jQuery('.mainwrapper').css({minHeight: windowHeight});
        }

        function responsive() {

            var windowWidth = jQuery(window).width();

            // hiding and showing left menu
            if (!jQuery('.showmenu').hasClass('clicked')) {

                if (windowWidth < 960)
                    hideLeftPanel();
                else
                    showLeftPanel();
            }

            // rearranging widget icons in dashboard
            if (windowWidth < 768) {
                if (jQuery('.widgeticons .one_third').length == 0) {
                    var count = 0;
                    jQuery('.widgeticons li').each(function() {
                        jQuery(this).removeClass('one_fifth last').addClass('one_third');
                        if (count == 2) {
                            jQuery(this).addClass('last');
                            count = 0;
                        } else {
                            count++;
                        }
                    });
                }
            } else {
                if (jQuery('.widgeticons .one_firth').length == 0) {
                    var count = 0;
                    jQuery('.widgeticons li').each(function() {
                        jQuery(this).removeClass('one_third last').addClass('one_fifth');
                        if (count == 4) {
                            jQuery(this).addClass('last');
                            count = 0;
                        } else {
                            count++;
                        }
                    });
                }
            }
        }

        // when resize window event fired
        jQuery(window).resize(function() {
            mainwrapperHeight();
            responsive();
        });

        // dropdown in leftmenu
        jQuery('.leftmenu .dropdown > a').click(function() {
            if (!jQuery(this).next().is(':visible'))
                jQuery(this).next().slideDown('fast');
            else
                jQuery(this).next().slideUp('fast');
            return false;
        });

        // hide left panel
        function hideLeftPanel() {
            jQuery('.leftpanel').css({marginLeft: '-260px'}).addClass('hide');
            jQuery('.rightpanel').css({marginLeft: 0});
            jQuery('.mainwrapper').css({backgroundPosition: '-260px 0'});
            jQuery('.footerleft').hide();
            jQuery('.footerright').css({marginLeft: 0});
        }

        // show left panel
        function showLeftPanel() {
            jQuery('.leftpanel').css({marginLeft: '0px'}).removeClass('hide');
            jQuery('.rightpanel').css({marginLeft: '260px'});
            jQuery('.mainwrapper').css({backgroundPosition: '0 0'});
            jQuery('.footerleft').show();
            jQuery('.footerright').css({marginLeft: '260px'});
        }

        // show and hide left panel
        jQuery('.showmenu').click(function() {
            jQuery(this).addClass('clicked');
            if (jQuery('.leftpanel').hasClass('hide'))
                showLeftPanel();
            else
                hideLeftPanel();
            return false;
        });

        // transform checkbox and radio box using uniform plugin
        if (jQuery().uniform)
            jQuery('input:checkbox, input:radio, select.uniformselect').uniform();


        // show/hide widget content or widget content's child	
        if (jQuery('.showhide').length > 0) {
            jQuery('.showhide').click(function() {
                var t = jQuery(this);
                var p = t.parent();
                var target = t.attr('href');
                target = (!target) ? p.next() : p.next().find('.' + target);
                t.text((target.is(':visible')) ? 'View Source' : 'Hide Source');
                (target.is(':visible')) ? target.hide() : target.show(100);
                return false;
            });
        }


        // check all checkboxes in table
        if (jQuery('.checkall').length > 0) {
            jQuery('.checkall').click(function() {
                var parentTable = jQuery(this).parents('table');
                var ch = parentTable.find('tbody input[type=checkbox]');
                if (jQuery(this).is(':checked')) {

                    //check all rows in table
                    ch.each(function() {
                        jQuery(this).attr('checked', true);
                        jQuery(this).parent().addClass('checked');	//used for the custom checkbox style
                        jQuery(this).parents('tr').addClass('selected'); // to highlight row as selected
                    });


                } else {

                    //uncheck all rows in table
                    ch.each(function() {
                        jQuery(this).attr('checked', false);
                        jQuery(this).parent().removeClass('checked');	//used for the custom checkbox style
                        jQuery(this).parents('tr').removeClass('selected');
                    });

                }
            });
        }


        // delete row in a table
        if (jQuery('.deleterow').length > 0) {
            jQuery('.deleterow').click(function() {
                var conf = confirm('Continue delete?');
                if (conf)
                    jQuery(this).parents('tr').fadeOut(function() {
                        jQuery(this).remove();
                        // do some other stuff here
                    });
                return false;
            });
        }
              
        /////////////////////////////// ELEMENTS.HTML //////////////////////////////


        // tabbed widget
        jQuery('#tabs, #tabs2').tabs();

        // accordion widget
        jQuery('#accordion, #accordion2').accordion({heightStyle: "content"});


        // color picker
        if (jQuery('#colorpicker').length > 0) {
            jQuery('#colorSelector').ColorPicker({
                onShow: function(colpkr) {
                    jQuery(colpkr).fadeIn(500);
                    return false;
                },
                onHide: function(colpkr) {
                    jQuery(colpkr).fadeOut(500);
                    return false;
                },
                onChange: function(hsb, hex, rgb) {
                    jQuery('#colorSelector span').css('backgroundColor', '#' + hex);
                    jQuery('#colorpicker').val('#' + hex);
                }
            });
        }


        // date picker
        if (jQuery('#datepicker').length > 0)
            jQuery("#datepicker").datepicker();


        // growl notification
        if (jQuery('#growl').length > 0) {
            jQuery('#growl').click(function() {
                jQuery.jGrowl("Hello world!");
            });
        }

        // another growl notification
        if (jQuery('#growl2').length > 0) {
            jQuery('#growl2').click(function() {
                var msg = "This notification will live a little longer.";
                jQuery.jGrowl(msg, {life: 5000});
            });
        }

        // basic alert box
        if (jQuery('.alertboxbutton').length > 0) {
            jQuery('.alertboxbutton').click(function() {
                jAlert('This is a custom alert box', 'Alert Dialog');
            });
        }

        // confirm box
        if (jQuery('.confirmbutton').length > 0) {
            jQuery('.confirmbutton').click(function() {
                jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
                    jAlert('Confirmed: ' + r, 'Confirmation Results');
                });
            });
        }

        // promptbox
        if (jQuery('.promptbutton').length > 0) {
            jQuery('.promptbutton').click
                    (function() {
                        jPrompt('Type something:', 'Prefilled value', 'Prompt Dialog', function(r) {
                            if (r)
                                alert('You entered ' + r);
                        });
                    });
        }

        // alert with html
        if (jQuery('.alerthtmlbutton').length > 0) {
            jQuery('.alerthtmlbutton').click(function() {
                jAlert('You can use HTML, such as <strong>bold</strong>, <em>italics</em>, and <u>underline</u>!');
            });
        }

        // sortable list
        if (jQuery('#sortable').length > 0)
            jQuery("#sortable").sortable();

        // sortable list with content-->
        if (jQuery('#sortable2').length > 0) {
            jQuery("#sortable2").sortable();
            jQuery('.showcnt').click(function() {
                var t = jQuery(this);
                var det = t.parents('li').find('.details');
                if (!det.is(':visible')) {
                    det.slideDown();
                    t.removeClass('icon-arrow-down').addClass('icon-arrow-up');
                } else {
                    det.slideUp();
                    t.removeClass('icon-arrow-up').addClass('icon-arrow-down');
                }
            });
        }

        // tooltip sample
        if (jQuery('.tooltipsample').length > 0)
            jQuery('.tooltipsample').tooltip({selector: "a[rel=tooltip]"});

        jQuery('.popoversample').popover({selector: 'a[rel=popover]', trigger: 'hover'});



        ///// MESSAGES /////	

        if (jQuery('.mailinbox').length > 0) {

            // star
            jQuery('.msgstar').click(function() {
                if (jQuery(this).hasClass('starred'))
                    jQuery(this).removeClass('starred');
                else
                    jQuery(this).addClass('starred');
            });

            //add class selected to table row when checked
            jQuery('.mailinbox tbody input:checkbox').click(function() {
                if (jQuery(this).is(':checked'))
                    jQuery(this).parents('tr').addClass('selected');
                else
                    jQuery(this).parents('tr').removeClass('selected');
            });

            // trash
            if (jQuery('.msgtrash').length > 0) {
                jQuery('.msgtrash').click(function() {
                    var c = false;
                    var cn = 0;
                    var o = new Array();
                    jQuery('.mailinbox input:checkbox').each(function() {
                        if (jQuery(this).is(':checked')) {
                            c = true;
                            o[cn] = jQuery(this);
                            cn++;
                        }
                    });
                    if (!c) {
                        alert('No selected message');
                    } else {
                        var msg = (o.length > 1) ? 'messages' : 'message';
                        if (confirm('Delete ' + o.length + ' ' + msg + '?')) {
                            for (var a = 0; a < cn; a++) {
                                jQuery(o[a]).parents('tr').remove();
                            }
                        }
                    }
                });
            }
        }


        // change layout
        jQuery('.skin-layout').click(function() {
            jQuery('.skin-layout').each(function() {
                jQuery(this).parent().removeClass('selected');
            });
            if (jQuery(this).hasClass('fixed')) {
                jQuery('.mainwrapper').removeClass('fullwrapper');
                if (jQuery('.stickyheaderinner').length > 0)
                    jQuery('.stickyheaderinner').removeClass('wideheader');
                jQuery.cookie("skin-layout", 'fixed', {path: '/'});
            } else {
                jQuery('.mainwrapper').addClass('fullwrapper');
                if (jQuery('.stickyheaderinner').length > 0)
                    jQuery('.stickyheaderinner').addClass('wideheader');
                jQuery.cookie("skin-layout", 'wide', {path: '/'});
            }
            return false;
        });

        // load selected layout from cookie
        if (jQuery.cookie('skin-layout')) {
            var layout = jQuery.cookie('skin-layout');
            if (layout == 'fixed') {
                jQuery('.mainwrapper').removeClass('fullwrapper');
                if (jQuery('.stickyheaderinner').length > 0)
                    jQuery('.stickyheaderinner').removeClass('wideheader');
            } else {
                jQuery('.mainwrapper').addClass('fullwrapper');
                if (jQuery('.stickyheaderinner').length > 0)
                    jQuery('.stickyheaderinner').addClass('wideheader');
            }
        }


        // change skin color
        jQuery('.skin-color').click(function() {
            var s = jQuery(this).attr('href');
            if (jQuery('#skinstyle').length > 0) {
                if (s !== 'default') {
                    jQuery('#skinstyle').attr('href', '<?php echo base_url("data/style/admin") ?>/css/style.' + s + '.css');
                    jQuery.cookie('skin-color', s, {path: '/'});
                } else {
                    jQuery('#skinstyle').remove();
                    jQuery.cookie("skin-color", '', {path: '/'});
                }
            } else {
                if (s !== 'default') {
                    jQuery('head').append('<link id="skinstyle" rel="stylesheet" href="<?php echo base_url("data/style/admin") ?>/css/style.' + s + '.css" type="text/css" />');
                    jQuery.cookie("skin-color", s, {path: '/'});
                }
            }
            return false;
        });

        // load selected skin color from cookie
        if (jQuery.cookie('skin-color')) {
            var c = jQuery.cookie('skin-color');
            if (c) {
                jQuery('head').append('<link id="skinstyle" rel="stylesheet" href="<?php echo base_url("data/style/admin") ?>/css/style.' + c + '.css" type="text/css" />');
                jQuery.cookie("skin-color", c, {path: '/'});
            }
        }

    });
	
	jQuery().ready(function() {
		jQuery('textarea.tinymce').tinymce({
			// Location of TinyMCE script
			script_url : '<?php echo base_url("data/style/admin") ?>/js/tinymce/tiny_mce.js',

			// General options
			theme : "advanced",
			skin : "themepixels",
			width: "100%",
			plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",
			inlinepopups_skin: "themepixels",
			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,outdent,indent,blockquote,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "pastetext,pasteword,|,bullist,numlist,|,undo,redo,|,link,unlink,image,help,code,|,preview,|,forecolor,backcolor,removeformat,|,charmap,media,|,fullscreen",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,

			// Example content CSS (should be your site CSS)
			content_css : "css/plugins/tinymce.css",

			// Drop lists for link/image/media/template dialogs
			template_external_list_url : "lists/template_list.js",
			external_link_list_url : "lists/link_list.js",
			external_image_list_url : "lists/image_list.js",
			media_external_list_url : "lists/media_list.js",

			// Replace values for the template plugin
			template_replace_values : {
				username : "Some User",
				staffid : "991234"
			}
		});
				
		
		jQuery('.editornav a').click(function(){
			jQuery('.editornav li.current').removeClass('current');
			jQuery(this).parent().addClass('current');
			if(jQuery(this).hasClass('visual'))
				jQuery('#elm1').tinymce().show();
			else
				jQuery('#elm1').tinymce().hide();
			return false;
	});
        
        jQuery('#dyntable').dataTable({
            "sPaginationType": "full_numbers",
            "aaSortingFixed": [[0, 'asc']],
            "fnDrawCallback": function(oSettings) {
//                jQuery.uniform.update();
            }
        });
});
</script>